#ifndef PRJ_MANAGER_TASK_WIDGET_H
#define PRJ_MANAGER_TASK_WIDGET_H

#include <QWidget>
#include <QTreeWidgetItem>
#include <QMenu>
#include "sqlite_manager.h"


namespace Ui {
class PrjManagerTaskWidget;
}

class PrjManagerTaskWidget : public QWidget
{
    Q_OBJECT

public:
    explicit PrjManagerTaskWidget(QWidget *parent = nullptr);
    ~PrjManagerTaskWidget();
    void setPrjUuid(QString uuid);
    void setTaskSelectMode();
    QHash<QString, QString> getCheckedTasks();
    QHash<QString, QString> getCheckedChildren(const QTreeWidgetItem* item);

private:
    void initUi();
    void initEvents();
    void initMenu();
    void initPrjTaskData();
    bool insertNewTask(QString uuid,
                       QString prjUuid,
                       QString parentTaskUuid,
                       QString taskName,
                       QString taskDescription,
                       QString createTime,
                       QString lastModifyTime,
                       QString taskStatus);
    bool updateTask(QString uuid,
                    QString parentTaskUuid,
                    QString taskName,
                    QString taskDescription,
                    QString lastModifyTime,
                    QString taskStatus);
    bool deleteTask(QString uuid);
    bool deleteChildTask(QString parentUuid);
    void deleteTreeWidgetItem(QTreeWidgetItem *item);
    void setDialogMode(bool isDialogMode);

signals:
    void accept();
    void reject();

private slots:
    void onNewTaskBtnClicked();
    void onNewChildTaskActionTriggered();
    void onEditTaskActionTriggered();
    void onDeleteTaskActionTriggered();
    void onDeleteChildTaskActionTriggered();

private:
    Ui::PrjManagerTaskWidget *ui;
    QString                   m_prjUuid;
    SqliteManager              *m_sqlOperator;
    QMenu                    *m_treeWidgetMenu;
    QTreeWidgetItem          *m_currentMenuAtItem;

};

#endif // PRJ_MANAGER_TASK_WIDGET_H
